function makePoster(cvs,img,color){
	// var cvs = document.getElementById('cvs');
	let cvs2d = cvs.getContext('2d'); 
	var imgCount = 0; 

	cvs2d.fillStyle = color;
	cvs2d.fillRect(0,0,746,790);

	cvs2d.fillStyle = "#fff";
	cvs2d.fillRect(0,790,746,1280);

	var img_icon = new Image; 
	img_icon.src = 'source/moonIco.jpg';
	imgCount++;
	// img_icon.setAttribute('crossOrigin', 'anonymous');
	img_icon.onload = function () {
		cvs2d.drawImage(img_icon, 65,64,130,130);
		drawImg();
	}

	cvs2d.fillStyle = '#fff';
	cvs2d.font = '30px WeibeiSCBold';  
	cvs2d.fillText('Jonny Pan 的私藏分享?',226,120); 

	cvs2d.fillStyle = '#fff';
	cvs2d.font = '25px KaiTi';  
	cvs2d.fillText('快扫码看看吧',226,172); 

	var img_mid = new Image; 
	img_mid.src = 'source/casb.jpg';
	imgCount++;
	// img_mid.setAttribute('crossOrigin', 'anonymous');
	img_mid.onload = function () {
		let height = 400
		let width = getWidthByHeight( this.width, this.height, height );
		let m_left = (cvs.width - width)/2;
		let m_top = 255;
		cvs2d.drawImage(img_mid, m_left, m_top, width, height); 
		drawImg();	
	}

	cvs2d.fillStyle = '#fff';
	cvs2d.font = '25px KaiTi';  
	cvs2d.fillText('砍价一元得月饼',65,745);

	var img_qr = new Image; 
	img_qr.src = 'source/od_qr.jpg';
	imgCount++;
	// img_qr.setAttribute('crossOrigin', 'anonymous');
	img_qr.onload = function () {  
		cvs2d.drawImage(img_qr, 70,870,305,305);
		drawImg();
	}

	var img_casb = new Image; 
	img_casb.src = 'source/casb.jpg';
	imgCount++;
	// img_casb.setAttribute('crossOrigin', 'anonymous');
	img_casb.onload = function () {  
		cvs2d.drawImage(img_casb, 470,926,147,230); 
		drawImg();
	}

	function getWidthByHeight( width,height,now_height ){
		return now_height / height * width;
	}

	function drawImg(){
		imgCount--;
		if(imgCount > 0 )
			return;
		// let img = document.getElementById('img');
		img.src = cvs.toDataURL("image/png")
	}
}

(function(){
	let clicker = document.getElementsByClassName('bottom-li-d');

	for(i=0;i<clicker.length;i++){
		clicker[i].onclick = function(){
			let cvs = document.getElementById('cvs');
			let img = document.getElementById('img');
			let color = this.style.backgroundColor;
			makePoster(cvs,img,color);
		}
	}

	let cvs = document.getElementById('cvs');
	let img = document.getElementById('img');
	makePoster(cvs,img,"#32a954");
})()
